import { createRouter, createWebHashHistory } from "vue-router";
import Home from "@/views/Home/index.vue";
import Login from "@/views/Login/index.vue";
import HelloWorld from "@/views/HelloWorld/index.vue";

const routes = [
  {
    path: "/",
    component: HelloWorld,
    // children
  },
  {
    path: "/home",
    component: Home,
  },
  {
    path: "/login",
    component: Login,
  },
  {
    path: "/account",
    component: () => import("@/views/Account/index.vue"),
    name: "Account",
  },
  {
    path: "/Library_home",
    component: () => import("@/views/Account/Library_home/index.vue"),
    name: "Library_home",
  },
  {
    path: "/search",
    component: () => import("@/views/Search/index.vue"),
    name: "Search",
  },
  {
    path: "/calendar",
    component: () => import("@/views/Calendar/index.vue"),
    name: "Calendar",
  },
  {
    path: "/rili",
    component: () => import("@/views/rili/index.vue"),
    name: "Rili",
    beforeEnter: (to, from, next) => {
      const quanxian = localStorage.getItem("quanxian");
      const quanxianArr = ["admin", "gg", "jdzr"];
      // admin gg jdzr
      next();
      // if (quanxianArr.includes(quanxian)) {
      //   next();
      // } else {
      //   alert("你没有权限");
      //   next({ name: from.name });
      // }
    },
  },
  {
    path: "/addCustomerInfo",
    component: () => import("@/views/addCustomerInfo/index.vue"),
    name: "addCustomerInfo",
  },
  {
    path: "/addCustomerInfo/choiceTags",
    component: () => import("@/views/addCustomerInfo/choiceTags.vue"),
    name: "choiceTags",
  },
  {
    path: "/addressCascader",
    component: () => import("@/views/addressCascader/index.vue"),
    name: "addressCascader",
  },
];
const router = createRouter({
  history: createWebHashHistory(),
  routes,
  scrollBehavior,
});

/**
 * 权限判定
 *
 */
router.beforeEach((to, from, next) => {
  next();
});
function scrollBehavior(to, from, savedPosition) {
  // `to` 和 `from` 都是路由地址
  // `savedPosition` 可以为空，如果没有的话。
  if (to.name === "Library_home") {
    return { top: 0 };
  }
}
export default router;
